<?php
require_once(__PHY_LIB.'/class/Item.class.php');

class uWorkSku extends Item {
/// definition and constructor ///
    function uWorkSku($id=0, $field="") {
        Query::Query();
        $this->cfgKeyField("id");
        $this->cfgAllField("id,work_id,size_id,kuang_id,price,price_en,stock,stock_locked,stock_max");
        $this->cfgTable("unit_work_sku");
        if ("" == $field || "*" == $field) {
            $this->cfgField($this->mAllField);
        }
        else {
            $this->cfgField($field);
        }
        if (0 < $id) {
            $this->cfgWhere($this->mKeyField . "=" . $id);
            $this->load();
        }
        else {
            $this->set($this->mKeyField, $id);
        }
    }

    function invalid() {
        if (!$this->get('work_id')) {
            return 'work_id';
        }
        if (!$this->get('size_id')) {
            return 'size_id';
        }

        return false;
    }

} /// end class uWorkSku.


class uWorkSkuList extends ItemList {
    /// definition and constructor ///
    function uWorkSkuList($tablename=null) {
        ItemList::ItemList();
        $this->cfgClass("uWorkSku");
        $this->cfgKeyField("id");
        $this->cfgAllField("id,work_id,size_id,kuang_id,price,price_en,stock,stock_locked,stock_max");
        $this->cfgTable(null == $tablename ? "unit_work_sku" : $tablename);
    }

} /// end class uWorkSkuList.


/// related functions ///
function uPrice($rSku) {
	if ('dollor' == $_SESSION['MONEY']) { // 美元
		return $rSku['price_en'];
	}
	else { // 人民币
		return $rSku['price'];
	}
}
?>
